/*
 * @Description: 优惠券类型组件
 * @Author: ziwei.ma
 * @Date: 2019-06-26 16:28:05
 * @Last Modified by: ziwei.ma
 * @Last Modified time: 2019-06-27 16:54:59
 */

<template>
  <item-base
    :option="option"
    @click.native="jumpToConpons(option.URL)"
  >
    <div slot="item-right">{{conponsNum}}</div>
  </item-base>
</template>

<script>
import { detectionGoToPage } from '@/utils/JumpUtils'
import { getCouponsCount } from '../api/api.js'
import ItemBase from './ItemBase'
export default {
  components: {
    'item-base': ItemBase
  },
  props: {
    option: ''
  },
  data() {
    return {
      conponsNum: '' // 显示的优惠券数量
      // isLogin: parseInt(getUserInfo().IS_LOGIN) // 获取的登录状态
    }
  },
  methods: {
    // 跳转至优惠券页面
    jumpToConpons(url) {
      detectionGoToPage(url)
    },
    // 获取优惠券数量
    getCouponsNum() {
      if (this.isLogin === 1) {
        getCouponsCount().then(res => {
          if (res > 0) {
            this.conponsNum = res
          }
        })
      } else {
        this.conponsNum = ''
      }
    }
  },
  mounted() {
    this.getCouponsNum()
  },
  computed: {
    isLogin() {
      return this.$store.getters.loginStatus
    },
    resumeCount() {
      return this.$store.getters.resumeCount
    }
  },
  watch: {
    resumeCount() {
      this.getCouponsNum()
    }
  }

}
</script>

<style scoped>
.list-icon {
  font-size: 40px;
  margin-right: 31px;
}
</style>
